


//
//  WMVideoMessageCell.m
//  RCIM
//
//  Created by 郑文明 on 16/4/20.
//  Copyright © 2016年 郑文明. All rights reserved.
//

#import "WMExcelMessageCell.h"
#import "WMExcelMessage.h"

@implementation WMExcelMessageCell

- (NSDictionary *)attributeDictionary {
    if (self.messageDirection == MessageDirection_SEND) {
        return @{
                 @(NSTextCheckingTypeLink) : @{NSForegroundColorAttributeName : [UIColor blueColor]},
                 @(NSTextCheckingTypePhoneNumber) : @{NSForegroundColorAttributeName : [UIColor blueColor]}
                 };
    } else {
        return @{
                 @(NSTextCheckingTypeLink) : @{NSForegroundColorAttributeName : [UIColor blueColor]},
                 @(NSTextCheckingTypePhoneNumber) : @{NSForegroundColorAttributeName : [UIColor blueColor]}
                 };
    }
    return nil;
}

- (NSDictionary *)highlightedAttributeDictionary {
    return [self attributeDictionary];
}
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self initialize];
    }
    return self;
}

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self initialize];
    }
    return self;
}
- (void)initialize {
    
            UIView *BackView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 70)];
            BackView.layer.masksToBounds = YES;
            BackView.layer.borderWidth = 1;
            BackView.layer.borderColor = [UIColor colorWithHexString:@"#333333"].CGColor;
            BackView.layer.cornerRadius =5;
            [self.messageContentView addSubview:BackView];
            self.showImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 50, 50)];
            self.showImageView.image = [UIImage imageNamed:@"chat_sendExcel"];
        //    self.showImageView.contentMode = UIViewContentModeCenter;
        //    [self.bubbleBackgroundView addSubview:self.showImageView];
            [BackView addSubview:self.showImageView];
        
            self.textLabel = [[RCAttributedLabel alloc]initWithFrame:CGRectMake(70, 10, 120, 50)];
            self.textLabel.textColor = [UIColor blackColor];
            self.textLabel.font = [UIFont systemFontOfSize:15];
            self.textLabel.numberOfLines = 2;
            [BackView addSubview:self.textLabel];
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    //    btn.backgroundColor = [UIColor yellowColor];
        [btn addTarget:self action:@selector(lookVideoWithUrl) forControlEvents:UIControlEventTouchUpInside];
        btn.alpha = 0.4;
        [BackView addSubview:btn];
        
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.messageContentView.mas_centerX);
            make.centerY.equalTo(self.messageContentView.mas_centerY).offset(-10);
            make.width.mas_equalTo(140);
            make.height.mas_equalTo(100);
        }];
    
}
+(CGSize)sizeForMessageModel:(RCMessageModel *)model withCollectionViewWidth:(CGFloat)collectionViewWidth referenceExtraHeight:(CGFloat)extraHeight{
    return     CGSizeMake(400, 120);
    
}
- (void)setDataModel:(RCMessageModel *)model {
    [super setDataModel:model];
    
    [self setAutoLayout];
}
- (void)setAutoLayout {

    if ([self.model.content isMemberOfClass:[WMExcelMessage class]]){
        
        WMExcelMessage *_textMessage = (WMExcelMessage *)self.model.content;
        
        [self.textLabel setText:_textMessage.extra];
        
    }
    
}
- (UIImage *)imageNamed:(NSString *)name ofBundle:(NSString *)bundleName {
    UIImage *image = nil;
    NSString *image_name = [NSString stringWithFormat:@"%@.png", name];
    NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
    NSString *bundlePath = [resourcePath stringByAppendingPathComponent:bundleName];
    NSString *image_path = [bundlePath stringByAppendingPathComponent:image_name];
    image = [[UIImage alloc] initWithContentsOfFile:image_path];
    
    return image;
}

- (void)longPressed:(id)sender {
    UILongPressGestureRecognizer *press = (UILongPressGestureRecognizer *)sender;
    if (press.state == UIGestureRecognizerStateEnded) {
        //DebugLog(@”long press end”);
        return;
    } else if (press.state == UIGestureRecognizerStateBegan) {
        [self.delegate didLongTouchMessageCell:self.model inView:self.bubbleBackgroundView];
    }
}
-(void)lookVideoWithUrl{
    if (self.lookVideoBtnClick) {
        self.lookVideoBtnClick();
    }
}
@end
